package com.alibaba.boot.netty;

import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.*;

public class TimerTest {

    private static BlockingQueue<String> blockQueue = new ArrayBlockingQueue<>(1000);

    public static void main(String[] args) {


        HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(1, TimeUnit.SECONDS);

        hashedWheelTimer.newTimeout(new TimerTask() {
            @Override
            public void run(Timeout timeout) throws Exception {
                System.out.println("task trigger now!");
            }
        },10,TimeUnit.SECONDS);

         new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        Thread.sleep(2000);
                    }catch (Exception e){

                    }
                }
            }
        }).start();


         new Thread(new Runnable() {
             @Override
             public void run() {
                 CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
                     @Override
                     public void run() {
                         try {
                             Thread.sleep(2000);
                         }catch (Exception e){

                         }
                         System.out.println("future trigger now!");
                     }
                 });
                 System.out.println("thread run stop");
             }
         }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    List<String> arr = new ArrayList<>();
                    blockQueue.drainTo(arr,100);
                    // todo 立马处理


                    if (blockQueue.size()<100){


                        try {
                            Thread.sleep(200);
                        }catch (Exception e){

                        }
                    }

                }
            }
        });

    }
}
